package com.example.rk.service.impl;

import com.example.rk.common.MyPageInfo;
import com.example.rk.entity.Job;
import com.example.rk.entity.Resume;
import com.example.rk.mapper.ResumeMapper;
import com.example.rk.service.ResumeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.lang.annotation.Annotation;
import java.util.List;

@Service
public class ResumeServiceImpl implements ResumeService {
    @Autowired
    private ResumeMapper adminMapper;

    @Override
    public MyPageInfo findBySearch(HttpServletRequest request, int id) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        String title = request.getParameter("title");
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        adminMapper.findBySearch(title,id);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());
        myPageInfo.setSearch1(title);
        return myPageInfo;
    }

    @Override
    public void doEdit1(int id) {
      adminMapper.doEdit1(id);

    }

    @Override
    public void doEdit2(int id) {
        adminMapper.doEdit2(id);
    }

    @Override
    public void deleteById(int id) {
        adminMapper.deleteById(id);
    }

    @Override
    public String doAdd(Resume resume) {
        Resume db=adminMapper.findadd(resume.getTitle());
        resume.setZt(2);
        if (db==null){
           adminMapper.create(resume);
            return "ok";
        }else{
            return "exist";
        }
    }

    @Override
    public Resume findById(int id) {
        return adminMapper.findById(id);
    }

    @Override
    public String doEdit(Resume resume) {
        try {
            adminMapper.doEdit(resume);
            return "ok";
        }catch (Exception e){
            System.out.println("RenKoServiceImpl.doEdit() ERROR:e="+e);
        }
        return "error";
    }

    @Override
    public MyPageInfo findBySearch1(HttpServletRequest request, int id) {
        int currentPageNum=1;  //当前页
        int pageSize=5;  //每页大小
        String currentPageNumStr = request.getParameter("pageNum");
        if (currentPageNumStr!=null){
            currentPageNum=Integer.parseInt(currentPageNumStr);
        }
        String title = request.getParameter("title");
        Page<Object> page = PageHelper.startPage(currentPageNum, pageSize);//必须在执行sql之前执行
        adminMapper.findBySearch1(title,id,1);
        PageInfo<Object> pageInfo = page.toPageInfo();
        MyPageInfo myPageInfo = new MyPageInfo(pageInfo.getPageNum(),pageInfo.getPageSize(),
                pageInfo.getNavigateLastPage(),pageInfo.getTotal(),pageInfo.getList());
        myPageInfo.setSearch1(title);
        return myPageInfo;
    }
}


